/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.uml_generator.manager.impl;

import com.genia.toolbox.uml_generator.manager.NameManager;
import com.genia.toolbox.uml_generator.model.AbstractObject;

/**
 * implementation of {@link NameManager}.
 */
public class NameManagerImpl
    implements NameManager
{
  /**
   * return the name of an {@link AbstractObject} with its first letter in lower
   * case.
   * 
   * @param object
   *          the {@link AbstractObject} to consider
   * @return the name of the {@link AbstractObject} with its first letter in
   *         lower case
   * @see com.genia.toolbox.uml_generator.manager.NameManager#getLowerCaseFirstLetterName(com.genia.toolbox.uml_generator.model.AbstractObject)
   */
  public String getLowerCaseFirstLetterName(AbstractObject object)
  {
    String name = object.getName();
    return name.substring(0, 1).toLowerCase() + name.substring(1);
  }



  /**
   * return the lower case name of an {@link AbstractObject} with an underscore
   * to separate words.
   * 
   * @param object
   *          the {@link AbstractObject} to consider
   * @return the lower case name of the {@link AbstractObject} with an
   *         underscore to separate words
   * @see com.genia.toolbox.uml_generator.manager.NameManager#getLowerUnderlineName(com.genia.toolbox.uml_generator.model.AbstractObject)
   */
  public String getLowerUnderlineName(AbstractObject object)
  {
    return getUnderlineName(object).toLowerCase();
  }



  /**
   * return the name of an {@link AbstractObject} with an underscore to separate
   * words.
   * 
   * @param object
   *          the {@link AbstractObject} to consider
   * @return the name of the {@link AbstractObject} with an underscore to
   *         separate words
   * @see com.genia.toolbox.uml_generator.manager.NameManager#getUnderlineName(com.genia.toolbox.uml_generator.model.AbstractObject)
   */
  public String getUnderlineName(AbstractObject object)
  {
    String name = object.getName();
    StringBuilder res = new StringBuilder();
    boolean last = true;
    for (int i = 0; i < name.length(); i++) {
      char c = name.charAt(i);
      if (!last && Character.isUpperCase(c)) {
        res.append('_');
      }
      else {
        last = false;
      }
      res.append(c);
    }
    return res.toString();
  }



  /**
   * return the name of an {@link AbstractObject} with its first letter in upper
   * case.
   * 
   * @param object
   *          the {@link AbstractObject} to consider
   * @return the name of the {@link AbstractObject} with its first letter in
   *         upper case
   * @see com.genia.toolbox.uml_generator.manager.NameManager#getUpperCaseFirstLetterName(com.genia.toolbox.uml_generator.model.AbstractObject)
   */
  public String getUpperCaseFirstLetterName(AbstractObject object)
  {
    String name = object.getName();
    return name.substring(0, 1).toUpperCase() + name.substring(1);
  }



  /**
   * return the upper case name of an {@link AbstractObject} with an underscore
   * to separate words.
   * 
   * @param object
   *          the {@link AbstractObject} to consider
   * @return the upper case name of the {@link AbstractObject} with an
   *         underscore to separate words
   * @see com.genia.toolbox.uml_generator.manager.NameManager#getUpperUnderlineName(com.genia.toolbox.uml_generator.model.AbstractObject)
   */
  public String getUpperUnderlineName(AbstractObject object)
  {
    return getUnderlineName(object).toUpperCase();
  }

}
